// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App' 
import routes from './router' //路由数据
import ElementUI from 'element-ui'
import axios from 'axios' // 处理http请求

import store from './store' // 状态管理
import 'element-ui/lib/theme-default/index.css'

import moment from 'moment'//时间过滤器
Vue.prototype.moment = moment
import '../static/js/time.js';

Vue.config.productionTip = false



require('./assets/common.scss')
import Mint from 'mint-ui'
import 'mint-ui/lib/style.css'//MintUI

import VeeValidate from 'vee-validate'
Vue.use(VeeValidate)

// import verify from "vue-verify-plugin";
// Vue.use(verify,{
//    blur:true
// });
// import VIscroll from 'viscroll';//滚动

Vue.use(VueRouter)
Vue.use(ElementUI)


//接口默认地址
axios.defaults.baseURL = 'http://222.77.181.149:998';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';



// export路由
export const router = new VueRouter({
  routes  
  // mode: 'hash', //可选参数 hash history
  // linkActiveClass: 'active' // 选中界面添加active
});

axios.interceptors.request.use(
  config => { 
    if (localStorage.getItem('tokendata')) {
      let Storagetoken = JSON.parse(localStorage.getItem('tokendata')).token;
      if (Storagetoken) {  // 判断是否存在token，如果存在的话，则每个http header都加上token
        config.headers.Authorization = 'BasicAuth' + " " + Storagetoken;
      }
     
    } return config;

  },
  err => {
    return Promise.reject(err);
  });

//路由拦截


router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (localStorage.getItem('tokendata')) {
      let Storagetoken = JSON.parse(localStorage.getItem('tokendata')).token;
      if (!Storagetoken) {
        next({
          name: '/login',
          query: {
            redirect: to.fullPath
          }
        });
    
    }
  }
  }
  next();
});



/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  Mint,
  template: '<App/>',
  components: { App }
})


